using Protocol.Constant;
using Protocol.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Assets.Scripts.Net.Impl
{
    public class ChatHandler : HandlerBase
    {
        private ChatMsg msg = new ChatMsg();

        public override void OnReceive(int subCode, object value)
        {
            switch (subCode)
            {
                case ChatCode.SRES:
                    ChatDto dto = value as ChatDto;
                    int userId = dto.UserId;
                    int chatType = dto.ChatType;
                    string text = Constant.GetChatText(chatType);

                    msg.UserId = userId;
                    msg.ChatType = chatType;
                    msg.Text = text;

                    Dispatch(AreaCode.UI, UIEvent.PLAYER_CHAT, msg);
                    Dispatch(AreaCode.AUDIO, AudioEvent.PLAY_EFFECT_AUDIO, "Chat/Chat_" + chatType);
                    break;
                default:
                    break;
            }
        }
    }
}
